package xyz.xtt.pay.controller;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.hutool.json.JSONUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.common.asset.AssertUtils;
import xyz.xtt.common.response.ApiResult;
import xyz.xtt.pay.client.request.BusinessOrderRequest;
import xyz.xtt.pay.client.response.BusinessOrderDto;
import xyz.xtt.pay.constants.ErrorMessage;
import xyz.xtt.pay.entity.TblBusinessOrder;
import xyz.xtt.pay.service.ITblBusinessOrderService;

@Tag(name = "businessOrder", description = "assistant")
@RefreshScope
@Slf4j
@RequestMapping("/api/nft/pay/businessOrder")
@RestController
public class BusinessOrderController {

	@Autowired
	private ITblBusinessOrderService tblBusinessOrderService;

	@Operation(summary = "根据商品查询订单列表")
	@PostMapping("/selectListByGoodsIds")
	public ApiResult<List<TblBusinessOrder>> selectListByGoodsIds(@RequestBody @Valid BusinessOrderRequest businessOrderRequest) {
		log.info("/api/asset/businessOrder/selectListByGoodsIds param:{}", JSONUtil.toJsonStr(businessOrderRequest));
		List<TblBusinessOrder> result = tblBusinessOrderService.selectListByGoodsIds(businessOrderRequest);
		AssertUtils.isNull(result, ErrorMessage.UNKNOWN_ERROR);
		return ApiResult.ok(result);
	}

	@Operation(summary = "根据ID批量查询数据")
	@PostMapping("/getByIds")
	public ApiResult<Map<Long, TblBusinessOrder>> getBusinessListByIds(@RequestBody Set<Long> ids) {
		return ApiResult.ok(tblBusinessOrderService.getBusinessByIds(ids));
	}

	@Operation(summary = "根据ID查询数据")
	@GetMapping("/getById")
	public ApiResult<BusinessOrderDto> getBusinessOrderById(@RequestParam Long businessOrderId) {
		return ApiResult.ok(tblBusinessOrderService.getBusinessOrderDtoById(businessOrderId));
	}
}
